<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>登录</title>
		<link rel="stylesheet" type="text/css" href="/public/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="/public/css/layout.css" />
		<script src="/public/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script src="/public/js/config.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body class="layui-layout-body">
		<div class="login_wapper">
			<div class="login_box">
				<h2><img src="/public/img/login_title.png" /></h2>
				<form class="layui-form" lay-filter="userLogin">
					<p class="err"></p>
					<dl>
						<dt>用户名：</dt>
						<dd>
							<input type="text" name="username" lay-verify="username" lay-verType="tips" autocomplete="off" placeholder="请输入用户名" class="txt">
						</dd>
					</dl>
					<dl>
						<dt>密　码：</dt>
						<dd>
							<input type="password" name="userpass" lay-verify="userpass" lay-verType="tips" autocomplete="off" placeholder="请输入密码" class="txt">
						</dd>
					</dl>
					<dl>
						<dt>验证码：</dt>
						<dd>
							<input type="text" name="captcha" lay-verify="captcha" lay-verType="tips" maxlength="4" autocomplete="off" placeholder="请输入验证码" class="txt">
						</dd>
						<dd><img src="/common/captcha" onclick="this.src='/common/captcha?'+Math.random();" /></dd>
					</dl>
					<dl>
						<dd><button type="submit" class="layui-btn layui-btn-normal" lay-submit lay-filter="login">立即提交</button></dd>
					</dl>
				</form>
			</div>
		</div>
		<script type="text/javascript">
			layui.use(['form', 'jquery', 'cookie'], function() {
				var $ = layui.jquery;
				var form = layui.form;
				form.verify({
					username: function(val) {
						if(val.length < 5) {
							return '标题至少得5个字符啊';
						}
					},
					userpass: [
						/^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格'
					],
					captcha:function(val){
						if(val.length <= 0) {
							return '请输入验证码';
						}else if($.cookie('captcha') !== val){
							return '验证码输入错误';
						}
					}
				});
				//监听提交
				form.on('submit(login)', function(data) {
					$.post('/admin/login', {
						username: data.field.username,
						userpass: data.field.userpass,
						captcha: data.field.captcha,
					}).then(data => {
						console.log(data);
					})
					return false;
				});
			});
		</script>
	</body>

</html>